package guda.house.dal.dao.impl;

import guda.grape.autogen.common.BaseDAO;
import guda.house.dal.dao.BillParkingDAO;
import guda.house.dal.dataobject.BillParkingDO;
import guda.grape.autogen.common.page.BaseQuery;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BillParkingDAOImpl extends BaseDAO implements BillParkingDAO {

    @Override
	public Long insert(BillParkingDO billParking) {
	      try {
                return (Long) getSqlMapperW().insert("bill_parking.insert",billParking);
          } catch (Exception e) {
                throw new RuntimeException(e);
          }

	}

    @Override
	public BillParkingDO getBillParkingById(Long billId) {
	    return (BillParkingDO)getSqlMapClientTemplate().queryForObject("bill_parking.getBillParkingById", billId);
	}

    @Override
	public boolean delBillParkingById(Long billId) {
	    int num = 0;
        try {
            num = getSqlMapperW().delete("bill_parking.delBillParkingById",billId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if(num>0){
            return true;
        }else{
            return false;
        }
	}

    @Override
	public List<BillParkingDO> getBillParkingByIds(List idsList) {
        Map m = new HashMap();
        m.put("idsList",idsList);
		return getSqlMapClientTemplate().queryForList("bill_parking.selectByIds", m);
	}

    @Override
	public void cleanAutoIncrement(Long billId) {
	    try {
            getSqlMapperW().update("bill_parking.cleanAutoIncrement",billId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
	}

    @Override
    public List<BillParkingDO> selectForPage(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("bill_parking.selectForPage", baseQuery);
    }

    @Override
    public int countForPage(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("bill_parking.countForPage",baseQuery);
    }

    @Override
    public void updateByIdSelective(BillParkingDO billParking) {
        try {
            getSqlMapperW().update("bill_parking.updateByIdSelective",billParking);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public List<BillParkingDO> getByYear(Long parkingId, Integer recordYear) {
        Map m = new HashMap();
        m.put("parkingId",parkingId);
        m.put("recordYear",recordYear);
        return getSqlMapClientTemplate().queryForList("bill_parking.getByYear", m);
    }

    @Override
    public List<BillParkingDO> selectForUnpay(BaseQuery baseQuery) {
        return getSqlMapClientTemplate().queryForList("bill_parking.selectForUnpay", baseQuery);
    }

    @Override
    public int countForUnpay(BaseQuery baseQuery) {
        return (Integer)getSqlMapClientTemplate().queryForObject("bill_parking.countForUnpay",baseQuery);
    }

    @Override
    public Long statBill(List<Long> parkingIdList, String gmtDate, Integer isPayed) {
        Map m = new HashMap();
        m.put("parkingIdList",parkingIdList);
        m.put("gmtDate",gmtDate);
        m.put("isPayed",isPayed);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_parking.statBill", m);
    }

    @Override
    public Long statBillRate(List<Long> suitIdList,Integer recordYear, Integer isPayed) {
        Map m = new HashMap();
        m.put("suitIdList",suitIdList);
        m.put("recordYear",recordYear);
        m.put("isPayed",isPayed);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_parking.statBillRate", m);
    }

    @Override
    public BillParkingDO selectLatest(Long suiteId) {
        return (BillParkingDO)getSqlMapClientTemplate().queryForObject("bill_parking.selectLatest", suiteId);
    }

    @Override
    public List<BillParkingDO> getByPayId(Long payId) {
        return getSqlMapClientTemplate().queryForList("bill_parking.getByPayId", payId);
    }

    @Override
    public Long statDichanDiscount(List<Long> parkingIdList, String gmtDate) {
        Map m = new HashMap();
        m.put("parkingIdList",parkingIdList);
        m.put("gmtDate",gmtDate);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_parking.statDichanDiscount", m);
    }

    @Override
    public Long statSelfDiscount(List<Long> parkingIdList, String gmtDate) {
        Map m = new HashMap();
        m.put("parkingIdList",parkingIdList);
        m.put("gmtDate",gmtDate);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_parking.statSelfDiscount", m);
    }

    @Override
    public List<BillParkingDO> statLastBill(List<Long> suiteIdList, Integer isPayed) {
        Map m = new HashMap();
        m.put("suiteIdList",suiteIdList);
        m.put("isPayed", isPayed);
        return getSqlMapClientTemplate().queryForList("bill_parking.statLastBill", m);
    }

    @Override
    public Long statPaidBill(List<Long> billIdList) {
        Map m = new HashMap();
        m.put("billIdList",billIdList);
        return (Long)getSqlMapClientTemplate().queryForObject("bill_parking.statPaidBill", m);
    }

}

